import React from "react";
import * as Icons from "@ant-design/icons";

/**
 * 递归生成路由
 */
export const generateRoutes = (menuData: any[]): any[] => {
  return menuData.map((item) => {
    // 动态加载图标
    const Icon = item.icon ? Icons[item.icon] : null;

    const route: any = {
      path: item.path,
      name: item.name,
      element: item.element || <div>{item.name}</div>, // 默认页面
      icon: Icon ? <Icon /> : null,
      hideInMenu: item.hideInMenu || false,
    };

    if (item.children) {
      route.children = generateRoutes(item.children); // 递归处理子菜单
    }

    return route;
  });
};